USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Insert]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert record into table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Insert]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Products](/*[Product_ID], [Product_Code], [ProductClassification_ID], [Product_NameAr], [Product_NameEn], [Product_Notes], [Product_Search]*/)
	VALUES     (/*@Product_ID, @Product_Code, @ProductClassification_ID, @Product_NameAr, @Product_NameEn, @Product_Notes, @Product_Search*/)

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
    WHERE  ( [Product_ID] =@Product_ID )
	AND  ( [Product_Code] =@Product_Code )
	AND  ( [ProductClassification_ID] =@ProductClassification_ID )
	AND  ( [Product_NameAr] =@Product_NameAr )
	AND  ( [Product_NameEn] =@Product_NameEn )
	AND  ( [Product_Notes] =@Product_Notes )
	AND  ( [Product_Search] =@Product_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Update record in table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-update]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Products] SET 
		/*[Product_ID] =@Product_ID, 
		[Product_Code] =@Product_Code, 
		[ProductClassification_ID] =@ProductClassification_ID, 
		[Product_NameAr] =@Product_NameAr, 
		[Product_NameEn] =@Product_NameEn, 
		[Product_Notes] =@Product_Notes, 
		[Product_Search] =@Product_Search*/
		/*WHERE ([Product_ID] = @Product_ID)*/
	/**/

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
	WHERE ([Product_ID] = @Product_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Insert-Update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert OR Update record into table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Insert-Update]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Products] 
					/*WHERE ([Product_ID] = @Product_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Products](/*[Product_ID], [Product_Code], [ProductClassification_ID], [Product_NameAr], [Product_NameEn], [Product_Notes], [Product_Search]*/)
		VALUES     (/*@Product_ID, @Product_Code, @ProductClassification_ID, @Product_NameAr, @Product_NameEn, @Product_Notes, @Product_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Products] SET 
			/*[Product_ID] =@Product_ID, 
			[Product_Code] =@Product_Code, 
			[ProductClassification_ID] =@ProductClassification_ID, 
			[Product_NameAr] =@Product_NameAr, 
			[Product_NameEn] =@Product_NameEn, 
			[Product_Notes] =@Product_Notes, 
			[Product_Search] =@Product_Search*/
			/*WHERE ([Product_ID] = @Product_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
	WHERE ([Product_ID] = @Product_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Delete]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	delete records from table [dbo].[Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Delete]
	/*@Product_RowNumber int =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Product_Notes varchar(max) =null  , 
	@Product_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Products]
	WHERE /*( [Product_RowNumber] = ISNULL(@Product_RowNumber, [Product_RowNumber]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Product_Notes] like ISNULL(@Product_Notes, [Product_Notes]) )
	AND ( [Product_Search] like ISNULL(@Product_Search, [Product_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Select]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	select records from table [dbo].[Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Select]
	/*@Product_RowNumber int =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Product_Notes varchar(max) =null  , 
	@Product_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Products]
	WHERE /*( [Product_RowNumber] = ISNULL(@Product_RowNumber, [Product_RowNumber]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Product_Notes] like ISNULL(@Product_Notes, [Product_Notes]) )
	AND ( [Product_Search] like ISNULL(@Product_Search, [Product_Search]) )*/
END
GO
-- =============================================
